package cn.fl.warrant.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.fl.warrant.service.IArcRouteDetailService;
import cn.fl.warrant.transform.ArcMgrDetailVOTransform;
import cn.fl.warrant.transform.ArcMgrMainVOTransform;
import cn.fl.warrant.transform.ArcRouteDetailVOTransform;
import cn.fl.warrant.vo.ArcMgrDetailVO;
import cn.fl.warrant.vo.ArcMgrMainVO;
import cn.fl.warrant.vo.ArcRouteDetailVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import fl.warrant.facade.archive.api.IArcRouteDetailApiService;
import fl.warrant.facade.archive.condition.ArcMgrMainQC;
import fl.warrant.facade.archive.condition.ArcRouteDetailQueryCondition;
import fl.warrant.facade.archive.dto.ArcMgrMainDTO;
import fl.warrant.facade.archive.dto.ArcRouteDetailDTO;

/**
 * @Description: 巡检明细表 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class ArcRouteDetailServiceImpl implements IArcRouteDetailService {

	/**
	 * 日志
	 */
	private static final Logger logger = LoggerFactory.getLogger(IArcRouteDetailService.class);
	
	/**
	 * TODO 自定义 API 暴露服务
	 */
	@Autowired
	private IArcRouteDetailApiService arcRouteDetailApiService;

	@Override
	public ArcRouteDetailVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "selectById", "主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		//TODO 业务逻辑
		ArcRouteDetailDTO dto = this.arcRouteDetailApiService.selectById(id);
		return ArcRouteDetailVOTransform.toVO(dto);
	}

	@Override
	public Long add(ArcRouteDetailVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "add", "新增对象不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		//return this.arcRouteDetailApiService.add(ArcRouteDetailVOTransform.toDTO(entity));
		//TODO 业务逻辑
		return null;
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "removeById", "删除主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		//return this.arcRouteDetailApiService.removeById(id);
		//TODO 业务逻辑
		return false;
	}
	
	/**
     * 删除
     * @param ids
     * @return
     */
    public boolean removeByIds(List<Long> ids)throws BaseException{
    	if(CollectionUtils.isEmpty(ids)){
    		BaseLogUtils.info(logger, "removeByIds", "删除主键参数集合不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		};
		return false;
    }

	@Override
	public boolean modify(ArcRouteDetailVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "modify", "修改对象参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		return this.arcRouteDetailApiService.update(ArcRouteDetailVOTransform.toDTO(entity));
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page)page = new Pager();
		return this.arcRouteDetailApiService.searchListPage(page);
	}

	@Override
	public List<ArcRouteDetailVO> searchList(ArcRouteDetailQueryCondition condition) throws BaseException {
		List<ArcRouteDetailDTO> list = this.arcRouteDetailApiService.searchList(condition);
		return ArcRouteDetailVOTransform.toVOList(list);
	}

	@Override
	public List<ArcMgrMainVO> getRandomRouteList(ArcMgrMainQC condition) throws BaseException {
		List<ArcMgrMainDTO> list = this.arcRouteDetailApiService.getRandomRouteList(condition);
		return ArcMgrMainVOTransform.toVOList(list);
	}

	@Override
	public boolean batchAddDetailInfo(List<ArcRouteDetailVO> vos) throws BaseException {
		if(null == vos){
			BaseLogUtils.info(logger, "batchAddDetailInfo", "新增对象不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		return this.arcRouteDetailApiService.batchAddDetailInfo(ArcRouteDetailVOTransform.toDTOList(vos));
	}

	@Override
	public boolean cancelDetailInfo(Long mainId) throws BaseException {
		if(StringUtils.isEmpty(mainId)){
			BaseLogUtils.info(logger, "cancelDetailInfo", "作废巡检明细数据,主表主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		return this.arcRouteDetailApiService.cancelDetailInfo(mainId);
	}

	@Override
	public boolean batchUpdateMgrDetailInfo(List<ArcMgrDetailVO> vos) throws BaseException {
		if(null == vos){
			BaseLogUtils.info(logger, "batchUpdateMgrDetailInfo", "修改对象不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		return this.arcRouteDetailApiService.batchUpdateMgrDetailInfo(ArcMgrDetailVOTransform.toDTOList(vos));
	}
	/**
	 * 导出巡检详情excel信息
	 */
	@Override
	public String exportRouteDetail(ArcRouteDetailQueryCondition condition,String eFlag)throws BaseException {
		return this.arcRouteDetailApiService.exportRouteDetail(condition,eFlag,CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
	}
}
